package stream._01introduction;

import stream.bean.Student;
import stream.bean.StudentList;

import java.util.Comparator;
import java.util.List;
import java.util.function.Consumer;
import java.util.function.Predicate;
import java.util.stream.Collectors;

public class Demo3 {
    public static void main(String[] args) {

        //使用Stream来处理
        List<Student> studentList = new StudentList().studentList;

        List<Student> list = studentList.stream().filter(new Predicate<Student>() {
            @Override
            public boolean test(Student student) {
                return student.getAddress() == Student.Address.BJ;
            }
        }).sorted(new Comparator<Student>() {
            @Override
            public int compare(Student o1, Student o2) {
                return o2.getHeight() - o1.getHeight();
            }
        }).limit(3).collect(Collectors.toList());
        list.forEach(new Consumer<Student>() {
            @Override
            public void accept(Student student) {
                System.out.println(student);
            }
        });

        List<Student> list2 = studentList.stream()
                .filter(student -> student.getAddress() == Student.Address.BJ)
                .sorted((s1, s2) -> s2.getHeight() - s1.getHeight())
                .limit(3)
                .collect(Collectors.toList());
        //list2.forEach(student -> System.out.println(student));
        list2.forEach(System.out::println);
    }

}
